package com.itheima.demo;

import java.io.FileReader;
import java.io.IOException;

/**
 * @author Zhang_Han
 * @version 1.0
 * @date 2020/7/10 18:51
 */
public class Demo_002 {
    public static void main(String[] args) throws IOException {

        FileReader fr = new FileReader("demo_IO\\name.txt");

        //int read()：一次读一个字符数据
        //  int ch;
        //  while ((ch=fr.read())!=-1) {
        //      System.out.print((char)ch);
        //  }

        //int read(char[] cbuf)：一次读一个字符数组数据
        //char[] chs = new char[1024];
        //int len;
        //while ((len = fr.read(chs)) != -1) {
        //    System.out.print(new String(chs, 0, len));
        //}
//
        ////释放资源
        //fr.close();
        //一次读一个字符数据
        //method01(fr);
        //int read(char[] cbuf)：一次读一个字符数组数据
        char [] chars = new char[1024];
        int len;
        while ((len = fr.read(chars))!=-1){
            System.out.println(new String(chars,0,len));
        }
        fr.close();
    }

    private static void method01(FileReader fr) throws IOException {
        int read = fr.read();
        System.out.println((char)read);
    }
}

